using System;
using System.Linq;
using System.Diagnostics.Contracts;

namespace ReactiveCode.Expressions
{
    using Observables;

    class ImperativeExpression<T>: ActionExpression<T>
    {
        Action<T> _body;

        internal override bool MarkAsCurrent
        {
            get { return false; }
        }

        public ImperativeExpression(ObservableFactory<IObservable<T>> trigger, Action<T> body)
        {
            Contract.Requires(trigger != null && body != null);
            Construct(trigger);
            _body = body;
        }

        protected override void Do(T arg)
        {
            _body(arg);
        }
    }
}